import 'package:earclean/app/config/colors.dart';
import 'package:earclean/app/modules/widget/app_bar_widget.dart';
import 'package:earclean/app/modules/widget/load_network_image_widget.dart';
import 'package:earclean/app/modules/widget/star_rating_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/pingjia_controller.dart';

class PingjiaView extends GetView<PingjiaController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget(titleStr: '技师评价'),
      body: Column(
        children: [
          Container(
            width: 1.sw,
            color: ColorConfig.white,
            margin: EdgeInsets.symmetric(
              vertical: 10,
            ),
            padding: const EdgeInsets.symmetric(
              horizontal: 12,
              vertical: 10,
            ),
            child: Row(
              children: [
                Expanded(
                  child: Text('用户评价',
                      style: TextStyle(
                          fontSize: 15.sp,
                          color: ColorConfig.app_main,
                          fontWeight: FontWeight.w600)),
                ),
                Obx(() => Text('近半年${controller.userComments.length}条评价',
                    style: TextStyle(fontSize: 11, color: Colors.red))),
              ],
            ),
          ),
          Expanded(child: tuijianWidget1())
        ],
      ),
    );
  }

  Widget tuijianWidget1() {
    return Obx(() => Container(
          width: 1.sw,
          child: ListView.separated(
              padding: EdgeInsets.zero,
              // shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemBuilder: ((context, index) {
                Map item = controller.userComments[index];
                return Container(
                  padding: EdgeInsets.symmetric(horizontal: 12, vertical: 10),
                  color: ColorConfig.white,
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        clipBehavior: Clip.hardEdge,
                        decoration: const BoxDecoration(
                          // border: Border.all(color: ColorConfig.app_main, width: .5),
                          borderRadius: BorderRadius.all(Radius.circular(8)),
                        ),
                        child: LoadNetworkImageWidget(
                            width: 75.r,
                            height: 75.r,
                            imageUrl: item['avatar'] ?? ''),
                      ),
                      const SizedBox(width: 15),
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            const SizedBox(height: 5),
                            Row(
                              children: [
                                Expanded(
                                  child: Text(item['nickname'] ?? '',
                                      style: TextStyle(
                                        fontSize: 16.sp,
                                        color: ColorConfig.text_label,
                                      )),
                                ),
                                Text("${item['datetime'] ?? ''}",
                                    style: TextStyle(
                                      fontSize: 14.sp,
                                      color: Color(0xFF787878),
                                    )),
                              ],
                            ),
                            Container(
                              alignment: Alignment.centerLeft,
                              child: starRating(
                                rating: 10,
                                size: 20,
                                count: item['score'] ?? 5,
                              ),
                            ),
                            Text("${item['content'] ?? ''}",
                                style: TextStyle(
                                  fontSize: 14.sp,
                                  color: Color(0xFF787878),
                                )),
                          ],
                        ),
                      ),
                    ],
                  ),
                );
              }),
              separatorBuilder: ((context, index) {
                return Container(height: 10);
              }),
              itemCount: controller.userComments.length),
        ));
  }
}
